package site.edody.dframe.websocket;


import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * webSocket 实例缓存
 * 单实例
 */
//@Component
public class WebSocketCache {

    private String listenerClass = "site.edody.dframe.websocket.SampleWsListener";

    private final ConcurrentHashMap<String, WebSocketServer> map = new ConcurrentHashMap<>();

    private final static WebSocketCache INSTANCE = new WebSocketCache();

    private WebSocketCache(){}

    public static WebSocketCache getInstance() {
        return INSTANCE;
    }

    public WebSocketServer getWebSocket(String sid){
        return map.get(sid);
    }

    public void setWebSocketServer (String sid,WebSocketServer ws){
        map.put(sid,ws);
    }

    public void remove(String sid){
        map.remove(sid);
    }

    public String getListenerClass() {
        return listenerClass;
    }

    public void setListenerClass(String listenerClass) {
        this.listenerClass = listenerClass;
    }
}
